Skip to content

Decouple the FileSource trait from the concrete FileScanConfig DataSource#23467

Draft
mitchsw wants to merge 1 commit into
apache:mainfrom
mitchsw:decouple-filesource-from-filescanconfig
Draft

Decouple the FileSource trait from the concrete FileScanConfig DataSource#23467
mitchsw wants to merge 1 commit into
apache:mainfrom
mitchsw:decouple-filesource-from-filescanconfig

Conversation

@mitchsw

@mitchsw mitchsw commented Jul 10, 2026

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

FileSource (the per-format scan trait) is currently coupled to its concrete FileScanConfig parent. A FileSource's open-time methods take a &FileScanConfig and use it as a "bag of args". That forces a custom DataSource to build a FileScanConfig it doesn't need just to reuse an existing FileSource. Passing those inputs explicitly in an arg struct decouples the two.

This PR strictly layers the types:

DataSourceExec ──► DataSource (trait) ──► FileScanConfig ──► FileSource (trait) ──► ParquetSource / ...

What changes are included in this PR?

  • Add FileSourceArgs, which FileSource::create_file_opener / create_morselizer now take instead of FileScanConfig base_config
  • Also pulls object_store and FileSource::with_batch_size into FileSourceArgs.
  • FileScanConfig builds FileSourceArgs inline in its open path (no-op).
  • Updates all FileSource implementations and the csv_json_opener example.

Why also remove with_batch_size?

Not strictly needed to close #23463 (the decoupling only needs the create_* signature change), but bundled as a cleanup:

  • batch_size is an open-time input like the others — it belongs in FileSourceArgs, not in a separate mutate-and-clone method.
  • It removes a runtime invariant: sources store Option<usize> and later .expect("Batch size must be set …"); a required arg is compiler-enforced.
  • The method is a single-purpose shim — one caller on main, and ArrowSource ignores its argument (fn with_batch_size(&self, _batch_size: usize)).
  • No extra breaking cost: the trait already changes here, so implementors update regardless.

Happy to drop this cleanup if reviewers prefer a narrower PR.

Are these changes tested?

Behavior is unchanged for the built-in FileScanConfig path, so existing scan tests cover it. cargo check/clippy/fmt and the core tests pass locally.

Are there any user-facing changes?

Yes, a breaking change to the public FileSource trait. Custom FileSource implementors must update. A simple migration guide is incliuded.

…l, via FileSourceArgs

FileSource::create_file_opener and create_morselizer took a &FileScanConfig, tying the file-format engines to that one concrete DataSource. A custom DataSource could not reuse an existing FileSource (e.g. ParquetSource) without first constructing a FileScanConfig.

Introduce FileSourceArgs, a small freely-constructible struct carrying the open-time inputs a FileSource needs (object_store, batch_size, limit, preserve_order, file_compression_type, expr_adapter_factory), and have both methods take &FileSourceArgs instead of &FileScanConfig. FileScanConfig builds it inline in open_with_args; a custom DataSource can build it the same way.

Also remove FileSource::with_batch_size: batch size now flows through FileSourceArgs, so sources no longer store it or guard it with an expect().

This opens the door for custom DataSource implementations to reuse FileSource without depending on FileScanConfig. Updates the Parquet/Csv/Json/Arrow/Avro sources, the test sources, the csv/json opener example, and adds a 55.0.0 upgrade note.
@github-actions github-actions Bot added documentation Improvements or additions to documentation core Core DataFusion crate datasource Changes to the datasource crate labels Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate datasource Changes to the datasource crate documentation Improvements or additions to documentation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple the FileSource trait from the concrete FileScanConfig DataSource

1 participant